﻿#region Opis pliku
//-----------------------------------------------------------------------------
// GameMenu.cs
// Autor: Jan Czarnowski
// 17.11.2012
//-----------------------------------------------------------------------------
#endregion

#region Using...

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;
using System.Collections.Generic;
using System;

#endregion

namespace pogra
{
    /// <summary>
    /// Klasa dziedzicząca z Menu, reprezentująca podręczne menu w trakcie rozgrywki, 
    /// w którym możemy zrestartować lub przerwać grę.
    /// </summary>
    class GameMenu : Menu
    {
        MenuItem continueButton;
        MenuItem restartButton;
        MenuItem quitButton;

        #region inicjalizacja

        public GameMenu()
        {
            title = "{ Menu }";
            isMovable = false;
            IsPopup = true;
        }

        public override void LoadContent()
        {
            Rectangle rectview = ScreenManager.ViewRect;
            menuRect.X = (rectview.Width - menuRect.Width) / 2;
            menuRect.Y = (rectview.Height - menuRect.Height) / 2;
            dragRect.X = menuRect.X;
            dragRect.Y = menuRect.Y;

            int menuItemHeight = 30;
            int menuItemWidth = menuRect.Width;

            continueButton = new MenuItem("Continue game", new Rectangle(menuRect.Left, dragRect.Bottom, menuRect.Width, menuItemHeight), this);
            restartButton = new MenuItem("Restart game", new Rectangle(menuRect.Left, dragRect.Bottom + menuItemHeight, menuRect.Width, menuItemHeight), this);
            quitButton = new MenuItem("Quit to menu", new Rectangle(menuRect.Left, dragRect.Bottom + 2 * menuItemHeight, menuRect.Width, menuItemHeight), this);

            itemList.Add(continueButton);
            itemList.Add(restartButton);
            itemList.Add(quitButton);
            loaded = true;
        }

        #endregion

        #region metody publiczne

        protected override void handleButtons(string pressedText)
        {
            if (pressedText == continueButton.Text)
            {
                IsActive = false;
            }
            else if (pressedText == restartButton.Text)
            {
                GamePlayScreen scrn = new GamePlayScreen();
                LoadingScreen.Load(ScreenManager, true, scrn, new GamePlayGUI(scrn));
            }
            else if (pressedText == quitButton.Text)
            {
                LoadingScreen.Load(ScreenManager, true, new MenuBackground(), new MainMenu());
            }

        }

        public override void HandleInput(InputState input, bool otherScreenHasFocus, ref bool eventHandled)
        {
            base.HandleInput(input, otherScreenHasFocus, ref eventHandled);

            if (input.IsNewKeyPress(Keys.Escape))
                IsActive = false;

            eventHandled = true;
        }

        #endregion
    }
}
